<?php

class Scaffold {

    var $tabela = "";
	private $registry;

    function Scaffold($registry, $table){
		$this->table = $table;
		$this->registry = $registry;
		
		//Redirecionar o caminho das views para o directorio do sistema de scaffold
		$this->registry['template']->setPath(site_path . 'scaffolding\views');
		
		//Defenir a tabela na BD
		$this->registry['db']->table = $table;
		
		
	}
	
	function listar(){
		
		$select = mysql_query("SELECT * FROM " .$this->registry['db']->table);
        $i = 0;
		$colunas = array();
		$tabela_data = array();
		
        
        while($i < mysql_num_fields($select)){
			
            $column = mysql_fetch_field($select, $i);
			array_push($colunas, $column);
			$i++;
        }
		
		while($array = mysql_fetch_array($select)){
			array_push($tabela_data, $array);
        }
		
		$this->registry['template']->set ('column_data', $colunas);
		$this->registry['template']->set ('tabela_data', $tabela_data);
		$this->registry['template']->set ('first_name', 'RoB scaffold System --- Listar');
		$this->registry['template']->set ('nome_tabela', $this->table);
		$this->registry['template']->show('header');
        $this->registry['template']->show('listar');
	}
}

?> 